package com.actionpals.net
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.HTTPStatusEvent;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.events.SecurityErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	/**
	 * Wrapper class for URLLoader and URLRequest.
	 * Allows access and usage of both from a single class for convenience.
	 * 
	 * @author	Mark Walters
	 * 
	 */
	public class URLRequestLoader extends EventDispatcher
	{
		private var _loader:URLLoader;
		private var _request:URLRequest;
		
		public function URLRequestLoader()
		{
			super( null );
			_loader = new URLLoader();
			_loader.addEventListener( Event.COMPLETE, completeHandler );
			_loader.addEventListener( HTTPStatusEvent.HTTP_STATUS, httpStatusHandler );
			_loader.addEventListener( IOErrorEvent.IO_ERROR, ioErrorHandler );
			_loader.addEventListener( Event.OPEN, openHandler );
			_loader.addEventListener( ProgressEvent.PROGRESS, progressHandler );
			_loader.addEventListener( SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler );
		}
		
		public function get bytesLoaded():uint
		{
			return _loader.bytesLoaded;
		}
		public function set bytesLoaded( value:uint ):void
		{
			_loader.bytesLoaded = value;
		}
		
		public function get bytesTotal():uint
		{
			return _loader.bytesTotal;
		}
		public function set bytesTotal( value:uint ):void
		{
			_loader.bytesTotal = value;
		}
		
		public function get data():*
		{
			return _loader.data;
		}
		public function set data( value:* ):void
		{
			_loader.data = value;
		}
		
		public function get dataFormat():String
		{
			return _loader.dataFormat;
		}
		public function set dataFormat( value:String ):void
		{
			_loader.dataFormat = value;
		}
		
		public function get request():URLRequest
		{
			return _request;
		}
		public function set request( value:URLRequest ):void
		{
			_request = value;
		}
		
		public function close():void
		{
			_loader.close();
		}
		
		public function load():void
		{
			_loader.load( request );
		}
		
		
		private function completeHandler( evt:Event ):void
		{
			dispatchEvent( evt );
		}
		
		private function httpStatusHandler( evt:HTTPStatusEvent ):void
		{
			dispatchEvent( evt );
		}
		
		private function ioErrorHandler( evt:IOErrorEvent ):void
		{
			dispatchEvent( evt );
		}
		
		private function openHandler( evt:Event ):void
		{
			dispatchEvent( evt );
		}
		
		private function progressHandler( evt:ProgressEvent ):void
		{
			dispatchEvent( evt );
		}
		
		private function securityErrorHandler( evt:SecurityErrorEvent ):void
		{
			dispatchEvent( evt );
		}
		
	}
}